Fragile binary interface problem
part 3/4 Β· 11.2 KB total
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
However, the market has selected programming languages such as C++ that are indeed "position dependent" and therefore exhibit FBI. In these cases there are still a number of solutions to the problem. One puts the burden on the library author by having them insert a number of "placeholder" objects in case they need to add additional functionality in the future (this can be seen in the structs used in the DirectX library). This solution works well until you run out of these dummies -- and you do not want to add too many because it takes up memory.
Objective-C 2.0 provides non-fragile instance variables by having an extra level of indirection for instance variable access.
Another partial solution is to use the Bridge pattern, sometimes known as "Pimpl" ("Pointer to implementation"). The Qt framework is an example of such an implementation. Each class defines only one data member, which is a pointer to the structure holding the implementation data. The size of the pointer itself is unlikely to change (for a given platform), so changing the implementation data does not affect the size of the public structure. However, this does not avoid other breaking changes such as introducing virtual methods to a class that has none, or changing the inheritance graph.
Linkers
Another solution requires a smarter linker. In the original version of Objective-C, the library format allowed for multiple versions of one library and included some functionality for selecting the proper library when called. However this was not always needed because the offsets were only needed for fields, since methods offsets were collected at runtime and could not cause FBI. Since methods tend to change more often than fields, ObjC had few FBI problems in the first place, and those it did could be corrected with the versioning system. Objective-C 2.0 added a "modern runtime" which solved the FBI problem for fields as well. Additionally, the TOM language uses runtime collected offsets for everything, making FBI impossible.
Using static instead of dynamic libraries where possible is another solution, as the library then cannot be modified without also recompiling the application and updating the offsets it uses. However static libraries have serious problems of their own, such as a larger binary and the inability to use newer versions of the library "automatically" as they are introduced.
Architecture
In these languages the problem is lessened by enforcing single inheritance (as this reduces the complexity of the inheritance tree), and by the use of interfaces instead of base classes with virtual functions, as interfaces themselves do not contain code, only a guarantee that each method signature the interface declares will be supported by every object that implements the interface.
Distribution method
The whole problem collapses if the source code of the libraries is available. Then a simple recompilation will do the trick.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ